﻿using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class DelProductsCommandHander : IRequestHandler<DelProductsCommand, ApiResult<object>>
    {
        public readonly IRepistory<Product> _productRepistory;

        public DelProductsCommandHander(IRepistory<Product> productRepistory)
        {
            _productRepistory = productRepistory;
        }
        public Task<ApiResult<object>> Handle(DelProductsCommand request, CancellationToken cancellationToken)
        {
           ApiResult<object> result = new ApiResult<object>();
            result.code = Renum.删除成功;
            result.Message=Renum.删除成功.ToString();
            foreach(var item in request.ProductsId)
            {
                var list = _productRepistory.GetAll().FirstOrDefault(x => x.ProductId == item);
                _productRepistory.Delete(list);
            }
            return Task.FromResult(result);
        }
    }
}
